// run: $exec < input
#include <iostream>
#include <cctype>

int a[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char b[] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};

int main()
{
	bool all = true;
	int n; std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::string s;
		std::cin >> s;
		int sum = 0;
		bool ok = true;
		for (int i = 0; i < 17; i++) {
			char ch = s[i];
			if (!isdigit(ch)) {
				ok = false;
			}
			sum += a[i] * (ch - '0');
		}
		sum %= 11;
		char ch = s[17];
		if (ch != b[sum]) ok = false;
		if (!ok) {
			all = false;
			std::cout << s << '\n';
		}
	}
	if (all)
		std::cout << "All passed\n";
}

